<cfcomponent displayname="ListDriver" hint="This class is a dictionary driver to manager List String" output="false">
	<cfscript>
		/**
		* 	Domain random Method
		* 	@name random
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-31
		*	@return String
		**/
		public String function random( String problem ) {
			var strDataSet 	   	= "";
			var totalItensList = ListLen( arguments.problem );
			var indexRemove	   	= 0;

			for( var idx = 1; idx <= totalItensList; idx++ ) {
				indexRemove  		= RandRange( 1, ( ( totalItensList + 1 ) -idx ) );
				strDataSet 			= ListAppend( strDataSet , ListGetAt( arguments.problem , indexRemove ) );

				arguments.problem 	= ListDeleteAt( arguments.problem , indexRemove );
			}

			return strDataSet;
		}

		/**
		* 	Domain cast some list data to array Method
		* 	@name asArray
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-23
		*	@return Array
		**/
		public Array function asArray( String data ) {
			var arrDataSet 	= [];
			var listSet  	= arguments.data;

			for( var idx = 1; idx <= ListLen( listSet ); idx++ ) {
				ArrayAppend( arrDataSet , ListGetAt( listSet , idx ) );
			}

			return arrDataSet;
		}

		/**
		* 	Domain cast some list data to query Method
		* 	@name asQuery
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-25
		*	@return Query
		**/
		public Query function asQuery( String data ) {
			var listData  	= arguments.data;
			var rsDataSet  	= QueryNew("data");

			rsDataSet = QueryNew( fieldList );

			for( var idx = 1; idx <= ListLen( listData ); idx++ ){
				QueryAddRow( rsDataSet );
				QuerySetCell( rsDataSet , "data" , ListGetAt( listData , idx ) );
			}

			return rsDataSet;
		}

		/**
		* 	get an item of object Method
		* 	@name getItem
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-28
		*	@return String
		**/
		public String function getItem( String data , String field = "" ,Any item ) {
			var strDataSet	= "";
			var ite			= arguments.item;
			var data		= arguments.data;
			var field		= arguments.field;

			try {
				variables.postItemLista = ListFind( data , item );
				strDataSet  = ( variables.postItemLista > 0 )? ListGetAt( data , variables.postItemLista ) : "";
			}
			catch( Any Ex ) {
				variables.error = Application.instance.factory.getModels("Error");
				variables.error.handlerError( Application.config.customExceptionUser , "Error of operation " );
			}

			return structDataSet;
		}

		/**
		* 	set data in the object Method
		* 	@name add
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-29
		*	@return String
		**/
		public String function add( String source , String data ) {
			var strDataSet	= arguments.source;
			var data		= arguments.data;

			strDataSet = ListAppend( strDataSet , data );

			return strDataSet;
		}

		/**
		* 	Domain determin sort field Method
		* 	@name asc
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-29
		*	@return String
		**/
		public String function asc( String field = "" ) {
			var order = "ASC";

			return order;
		}

		/**
		* 	Domain determin sort field Method
		* 	@name desc
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-29
		*	@return String
		**/
		public String function desc( String field = "" ) {
			var order = "DESC";

			return order;
		}

		/**
		* 	Domain sort data Method
		* 	@name sort
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-29
		*	@return String
		**/
		public String function sort( String recordSet , String filter ) {
			var strRecordSet = {};
			var recordSet	= arguments.recordSet;
			var filter 		= arguments.filter;

			strRecordSet = ListSort( recordSet , "text" , filter );

			return strRecordSet;
		}
	</cfscript>
</cfcomponent>